package com.softeem.hbsmvideo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.softeem.hbsmvideo.entity.Category;
import com.softeem.hbsmvideo.entity.Comment;
import com.softeem.hbsmvideo.entity.User;
import com.softeem.hbsmvideo.entity.Video;
import com.softeem.hbsmvideo.service.CommentService;
import com.softeem.hbsmvideo.service.UserService;
import com.softeem.hbsmvideo.service.VideoService;
import com.softeem.hbsmvideo.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*
* 视频评论的业务接口
* */
@RequestMapping("/comment")
@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;

    @Autowired
    private UserService userService;

    @Autowired
    private VideoService videoService;
    @GetMapping("/list")
    public R list(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "5") Integer limit){
        List<Comment> list = commentService.list(new Page<Comment>(page, limit));

        list.forEach(c->{
            //获取作者id
            Integer uid=c.getUid();
            //获取频道id
            Integer vid=c.getVid();
            //根据作者id查询作者
            User user = userService.getById(uid);
            Video video= videoService.getById(vid);
            c.setUser(user);
            c.setVideo(video);
        });

        Long count=commentService.count();
        return R.ok("查询成功").setData(list).setCount(count);

    }

}
